package com.service.impl;

import com.bean.entity.*;
import com.bean.vo.StudentInfoVo;
import com.bean.vo.TeachersVo;
import com.dao.*;
import com.service.UtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
/**
* 本方法是添加学生成绩的工具类
* */
@Service
public class UtilServiceImpl implements UtilService {
    @Autowired
    private StudentScoreMapper studentScoreMapper;
    @Autowired
    private StudentInfoMapper studentInfoMapper;
    @Autowired
    private SubjectInfoMapper subjectInfoMapper;
    @Autowired
    private TeachersMapper teachersMapper;
    @Autowired
    private TestInfoMapper testInfoMapper;
    @Override
    public void AddScoreUtil(int num) {
        List<StudentInfoVo> studentIdList = studentInfoMapper.select(new StudentInfo());

        List<SubjectInfo> subjectIdList = subjectInfoMapper.select(new SubjectInfo());

        List<TeachersVo> teacherIdList = teachersMapper.select(new Teachers());

        List<TestInfo> testTimeList = testInfoMapper.select(new TestInfo());

        //像分数里面随机添加300条数据
        for (int i = 0; i <num ; i++) {
            Long studentId=Long.valueOf(studentIdList.get((int)(Math.random()*studentIdList.size())).getId());
            Long classesId=Long.valueOf((studentId+"").substring(0,4));
            Integer subjectId=Integer.valueOf(subjectIdList.get((int)(Math.random()*subjectIdList.size())).getId());
            Integer teacherId=Integer.valueOf(teacherIdList.get((int)(Math.random()*teacherIdList.size())).getId());
            Double score=Double.valueOf(((int)(Math.random()*150+1)));
            Date testTime=testTimeList.get((int)(Math.random()*testTimeList.size())).getTestTime();
            studentScoreMapper.insert(new StudentScore(studentId,classesId,subjectId,teacherId,score,testTime));
            System.out.println("添加成功"+i+"次");
        }
    }
}
